package com.wangp.mywrite.s_juc.concurrtent_tools;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Semaphore;

/**
 * @author tooStronger
 * @date 2023/5/16
 */
@Slf4j
public class SemaphoreTest {

    private static final Semaphore SEMAPHORE = new Semaphore(3);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                try {
                    SEMAPHORE.acquire();
                    log.info("获取到信号开始执行");
                    Thread.sleep(1000);
                    SEMAPHORE.release();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }

        Thread.sleep(10000L);
    }

}
